<template>
  <!-- 分析系统(项目)知识库 -->
  <div id="knowledgeBaseByAns">
    <div ref="contentDetail"  :style="{ width: '100%' }">
      <div class="title text-bold padding-left-sm" :style="{ marginTop:'0'}">基本信息：</div>
      <el-descriptions  :column="3"  size="small" labelClassName="description-label" contentClassName="description-content" border style="margin: 10px 0">
        <el-descriptions-item label="项目编号">
          <span>{{ itemData.feeCode }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="项目名称">
          <span>{{ itemData.feeName }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="缩写">
          <span>{{ itemData.inputCode }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="所属分组">
          <span>{{ itemData.exaMethod ? `${itemData.exaMethod.name}(${itemData.exaMethod.code})` : '' }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="单位">
          <span>{{ itemData.defaultResult }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="标准单价">
          <span>{{ itemData.price }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="启用人">
          <span>{{ itemData.enableEmployee ? itemData.enableEmployee.name : '' }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="启用时间">
          <span>{{ itemData.enableTime }}</span>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div :ref="'contentDetail' + index" v-for="(item, index) in showTabs" :data-index="index" :key="index" :style="{ width: 'calc(100% - 300px)' }">
      <div class="title text-bold padding-left-sm" :style="{ marginTop: '20px' }">{{ item.label }}：</div>
      <div class="content">{{ knowledgeBase[item.value] || '暂无数据' }}</div>
    </div>
    <el-card @click.native="toTabDetail">
      <div :ref="'tabLabel' + index" v-for="(item, index) in showTabs" :key="index" :data-index="index">{{ `${index + 1}、${item.label}` }}</div>
    </el-card>
  </div>
</template>
<script lang="ts" setup>
import { IsEmpty } from '@/utils/common';
import {getCurrentInstance, reactive, ref} from "vue";

let { proxy }: any = getCurrentInstance();

let ansId = ref('');
let loading = ref(false); //添加弹框展示状态
let itemData = reactive({});
let knowledgeBase = reactive({});

let showTabs = reactive([])
defineExpose({
  findKnowledgeBaseByAnsList
})

  //获取列表
function findKnowledgeBaseByAnsList(row :any) {
  Object.assign(knowledgeBase,null)
  if (IsEmpty(row.feeItemId)) {
      proxy.$XModal.message({ content: '请选择需要查看的项目', status: 'error' });
      Object.assign(itemData,null)
      return;
    }
  Object.assign(itemData,row)

  loading.value = true;
  const url = '/api/sys/sysextenfieldsvalue/findExtenFieldsValueList';
  proxy.$http
      .get(url,{
        params: {
          moduleId: '1716657789982969857',
          menuId: '1734129954829893633',
          tabKey: '001',
          busRowId: row.feeItemId
        }
      })
      .then((res: any) => {
        for (const item of res.data.data) {
          const tab= {
            value: item.fieldCode,
            label: item.fieldName
          }
          showTabs.push(tab)
        }
        for (const item of res.data.data) {
          knowledgeBase[item.fieldCode]=item.value
        }
        console.log('knowledgeBase',knowledgeBase)
        loading.value = false;
      })
      .catch(err => {
        loading.value = false;
        proxy.$alert(err.data.error.message, '提示');
      });
  }
  // 滚动条定位
function toTabDetail(e) {
    const index = e.target.dataset.index;
    const $tab = proxy.$refs['contentDetail' + index][0];
    $tab.scrollIntoView();

    showTabs.forEach((tab, i) => {
      (proxy.$refs['tabLabel' + i][0] as any).className = '';
    });
    (proxy.$refs['tabLabel' + index][0] as any).className = 'active-label';
  }

</script>
<style lang="scss" scoped>
@import '@/assets/css/isd-body.scss';
#knowledgeBaseByAns {
  background: #fff;
  padding: 0 10px;
  line-height: 2em;
  font-size: 1.3em;
  .el-descriptions {
    .description-label {
      width: 120px;
      min-width: 60px;
      color: #000;
    }
    .description-content {
      width: 400px;
      color: #000;
    }
    .el-descriptions-item__cell {
      border-color: #ddd;
    }
  }
  .title {
    position: relative;
    font-size: 1.1em;
  }
  .title::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 60%;
    top: 25%;
    left: 0;
    background: $brand-color;
  }
  .content {
    text-indent: 2em;
  }

  .el-card {
    position: fixed;
    right: calc((100% - 1000px) / 2);
    top: 220px;
    .el-card__body {
      padding: 15px 0;
      > div {
        padding: 5px 20px;
      }
      > div:hover {
        background: #eee;
        cursor: pointer;
      }
      .active-label {
        color: $brand-color;
      }
    }
  }
}
</style>
